<script lang="ts" setup>
	import {
		useRouter
	} from 'uni-mini-router'
	import {
		userStore
	} from '@/pinia';
	import {
		getCurrentInstance
	} from 'vue'
	const {
		proxy,
	} = getCurrentInstance()
	const userStoreInfo = userStore();
	let router = useRouter()
	const routerLink = (id, index) => {
		uni.$on('serviceLike', (data) => {
			props.list[index].like = data.like
			props.list[index].likeNum = data.likeNum
			props.list[index].collect = data.collect
			props.list[index].collectNum = data.collectNum
			uni.$off('serviceLike')
		})
		if (props.type != 1) {
			//type1||3代表证书或者装修
			router.push({
				name: 'serviceRichDetail',
				params: {
					id,
					type: props.type,
					serviceType: props.serviceType
				}
			})
		} else {
			router.push({
				name: 'serviceMakeover',
				params: {
					id,
					serviceType: props.serviceType
				}
			})
		}
		setTimeout(() => {
			props.list[index].viewNum++
		}, 600)
	}
	let props = defineProps(['type', 'tab', 'list', 'serviceType'])
	console.log(props, "打印props")
	const likeAndCollect = (type1, type2, id, index) => {
		proxy.$req('POST', proxy.$api.likeAndCollect, {
			id: id,
			moduleType: 7,
			operateType: type1,
			updateType: type2,
			serviceType: props.serviceType,
			userId: userStoreInfo.userInfo.id
		}).then((res) => {
			console.log(res);
			uni.showToast({
				title: res.message,
				icon: 'none'
			})
			if (type1 == 0 && type2 == 'like') {
				props.list[index].like = 1
				props.list[index].likeNum++
			} else if (type1 == 0 && type2 == 'unlike') {
				props.list[index].like = null
				props.list[index].likeNum--
			} else if (type1 == 1 && type2 == 'collect') {
				props.list[index].collect = 1
				props.list[index].collectNum++
			} else if (type1 == 1 && type2 == 'uncollect') {
				props.list[index].collect = null
				props.list[index].collectNum--
			}
		})
	}
</script>
<template>
	<view class="markCon" @click="routerLink(item.id,index)" v-for="(item,index) in props.list" :key="index">
		<image class="mcLeft" :src="item.images.length>0?JSON.parse(item.images)[0].url:''" mode=""></image>
		<view class="mcRight">
			<view class="mcr1 u-line-2">
				{{ item.title }}
			</view>
			<view class="mcr2">
				<view class="msgShell r-flex-center-center">
					<!-- <image src="../../static/icon/message.png" mode=""></image> -->
					<view class="r-flex-center-center">
						<u-icon name="chat" color="#fff" size="40rpx"></u-icon>
					</view>
				</view>
			</view>
			<view class="mcr3">
				<view class="" @click.stop="likeAndCollect(0,item.like==null?'like':'unlike',item.id,index)">
					<u-icon :name="item.like?'thumb-up-fill':'thumb-up'" :color="item.like?'#CB645E':'' "></u-icon>
					<text :style="{color:item.like?'#CB645E':''}">{{ item.likeNum >0?item.likeNum:0}}</text>
				</view>
				<view class="" @click.stop="likeAndCollect(1,item.collect==null?'collect':'uncollect',item.id,index)">
					<u-icon :name="item.collect?'heart-fill':'heart' " :color="item.collect?'#CB645E':'' "></u-icon>
					<text :style="{color:item.collect?'#CB645E':''}">{{ item.collectNum >0?item.collectNum:0}}</text>
				</view>
				<view class="">
					<u-icon name="eye"></u-icon>
					<text>{{ item.viewNum }}</text>
				</view>
			</view>
		</view>
	</view>
</template>
<style lang="scss">
	.markCon {
		box-sizing: border-box;
		width: 686rpx;
		height: 264rpx;
		margin: 24rpx auto;
		display: flex;
		align-items: center;
		justify-content: space-between;
		box-shadow: 8rpx 8rpx 32rpx 0rpx rgba(0, 0, 0, 0.04);
		border-radius: 24rpx;
		border: 2rpx solid #FFFFFF;
		background: #FFFFFF;
		padding: 32rpx;

		.mcLeft {
			width: 176rpx;
			height: 200rpx;
			border-radius: 8rpx;
		}

		.mcRight {
			width: 426rpx;
			height: 200rpx;

			.mcr1 {
				width: 100%;
				height: 80rpx;
				font-size: 28rpx;
				color: rgba(0, 0, 0, 0.85);
				font-weight: 400;
				margin-top: 6rpx;
			}

			.mcr2 {
				display: flex;
				justify-content: flex-end;

				.msgShell {
					width: 100rpx;
					height: 48rpx;
					border-radius: 8rpx;
					background-color: #CB645E;

					image {
						width: 40rpx;
						height: 34rpx;
					}
				}
			}

			.mcr3 {
				width: 100%;
				height: 70rpx;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				view {
					display: flex;
					align-items: center;

					text {
						font-size: 24rpx;
						font-weight: 400;
						color: rgba(0, 0, 0, 0.65);
						margin-right: 15rpx;
						margin-left: 6rpx;
					}
				}
			}
		}
	}
</style>